<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .content {
            width: 230px;
        }
        
        .item {
            display: flex;
            justify-content: space-between;
        }
    </style>
</head>

<body>
    <div>
        <textarea rows="3" id="text">

		</textarea>
        <button id="bn">发布</button>
    </div>
    <div class="content">
    </div>
</body>
<script>
    //1.首先点击按钮绑定点击事件
    //2.取到文本域里面的值
    //3.创建一个item 、显示的div、删除div
    var bn = document.getElementById('bn');
    var content = document.querySelector('.content');
    bn.onclick = function() {
        var text = document.querySelector('#text');
        console.log(text.value);
        var rowDiv = document.createElement('div');
        rowDiv.classList.add('item');
        var textDiv = document.createElement('div');
        var delDiv = document.createElement('div');
        delDiv.innerHTML = '删除';
        textDiv.innerHTML = text.value;
        delDiv.addEventListener('click', function() {
            content.removeChild(this.parentNode);
            text.value = '';
        });
        rowDiv.appendChild(textDiv);
        rowDiv.appendChild(delDiv);
        content.appendChild(rowDiv);
        text.value = '';


    }
</script>

</html>